#include "monthlyattendancewidget.h"
#include "ui_monthlyattendancewidget.h"
#include <QSqlQuery>
#include <QSqlError>
#include "loginwidget.h"
#include <QDebug>

MonthlyAttendanceWidget::MonthlyAttendanceWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MonthlyAttendanceWidget)
{
    ui->setupUi(this);
    initWindow();
}

MonthlyAttendanceWidget::~MonthlyAttendanceWidget()
{
    delete ui;
}

/**
 * @brief 初始化窗体
 */
void MonthlyAttendanceWidget::initWindow()
{
    this->setWindowTitle("月度出勤");
    QSqlQuery query;
    query.prepare("SELECT username FROM user WHERE role = 2");
    if(!query.exec())
    {
        qDebug() << query.lastError();
    }
    else
    {
        while(query.next())
        {
            QString username = query.value(0).toString();
            ui->cb_user->addItem(username);
        }
    }
}

/**
 * @brief 查询
 */
void MonthlyAttendanceWidget::on_btn_query_clicked()
{
    QString username = ui->cb_user->currentText();
    widget = new CalendarWidget(this);
    widget->setUserName(username);
    widget->show();
}
